< previous page page_287 next page >

Page 287
e10a6a0a59f035e870d90cca05b85fce.gif
Dim y1 As Integer
Dim x2 As Integer
Dim y2 As Integer
Dim status As Integer
Dim num_bends As Integer
Dim num_branches As Integer
Dim i As Integer
Dim new_length As Integer
Dim new_theta As Single
Dim new_bend As Single
Dim dt As Single
Dim t As Single

    If thickness > 0 Then picCanvas.DrawWidth = thickness

    ' Draw the branch.
    If bend > 0 Then
        ' This is a bending branch.
        num_bends = length / DIST_PER_BEND
        t = theta
        x1 = X
        y1 = Y
        For i = 1 To num_bends
            x2 = x1 + DIST_PER_BEND * Cos(t)
            y2 = y1 + DIST_PER_BEND * Sin(t)
            picCanvas.Line (x1, y1)-(x2, y2)

            t = t + bend * (Rnd - 0.5)
            x1 = x2
            y1 = y2
        Next i
    Else
        ' This is a straight branch.
        x1 = X + length * Cos(theta)
        y1 = Y + length * Sin(theta)
        picCanvas.Line (X, Y)-(x1, y1)
    End If

    ' If depth > 1, draw the attached branches.
    If Depth > 1 Then
        num_branches = Int((max_branches - 1) * Rnd + 2)
        dt = 2 * dtheta / (num_branches - 1)
        t = theta - dtheta
        For i = 1 To num_branches
            new_length = length * _
                (length_scale + rnd_scale * (Rnd - 0.5))
            new_theta = t + rnd_dtheta * (Rnd - 0.5)
            t = t + dt
            If bend > 0 Then
                new_bend = bend * BEND_FACTOR
                If new_bend > MAX_BEND Then _

 
< previous page page_287 next page >